#include "include/shortcutwidget.h"
#include "ui_shortcutwidget.h"


namespace
{

	const char* NoneText = "None";

} //private namespace


ShortcutWidget::ShortcutWidget(QWidget *parent) :
	QWidget(parent),
	ui(new Ui::ShortcutWidget)
{
	ui->setupUi(this);
	setupIcons();
}

ShortcutWidget::~ShortcutWidget()
{
	delete ui;
}

void ShortcutWidget::resetCustomShortcut()
{
	ui->shortcutInput->resetSequence();
}

void ShortcutWidget::customShortcutChanged()
{
	ui->rbCustom->setChecked(true);
	ui->rbCustom->setFocus();
}


QKeySequence ShortcutWidget::defaultSequence() const
{
	return _defaultSequence;
}

QKeySequence ShortcutWidget::customSequence() const
{
	return ui->shortcutInput->sequence();
}

QKeySequence ShortcutWidget::currentSequence() const
{
	if (ui->rbCustom->isChecked())
		return ui->shortcutInput->sequence();

	return _defaultSequence;
}

void ShortcutWidget::setSequences(const QKeySequence& defaultSequence, const QKeySequence& currentSequence)
{
	_defaultSequence = defaultSequence;

	QString defaultText = defaultSequence.isEmpty() ? tr(NoneText) : defaultSequence.toString();
	ui->leDefault->setText(defaultText);

	if (defaultSequence == currentSequence)
	{
		ui->shortcutInput->resetSequence();
		ui->rbDefault->setChecked(true);
	}
	else
	{
		ui->shortcutInput->setSequence(currentSequence);
		ui->rbCustom->setChecked(true);
	}
}

void ShortcutWidget::setupIcons()
{
//	ui->bReset->setIcon(QIcon::fromTheme("edit-clear"));
}

